package com.eeepay.eeepay_v2.activity;

import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.adapter.OrderResultAdapter;
import com.eeepay.eeepay_v2.model.OrderResult;
import com.eeepay.eeepay_v2.util.TimeUtils;
import com.eeepay.v2_library.ui.ABBaseActivity;
import com.eeepay.v2_library.view.TitleBar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Ching on 2016/3/30.
 * 订单查询界面
 */
public class OrderQueryActivity extends ABBaseActivity implements TitleBar.RightBtnOnClickListener, RadioGroup.OnCheckedChangeListener, View.OnClickListener {

    private TitleBar titleBar;
    private RadioGroup statusRg;
    private Button confirmBtn;
    private LinearLayout resultView, queryView;
    private TextView startTv, endTv;
    private ListView resultLv;

    private String status;//选择的状态
    private String startTime, endTime;//获取选择的时间
    private String rightText;

    private OrderResultAdapter adapter;
    private List<OrderResult> list;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_order_query;
    }

    @Override
    protected void initWidget() {

        titleBar = getViewById(R.id.tb_order_query);
        statusRg = getViewById(R.id.rg_order_status);
        confirmBtn = getViewById(R.id.btn_order_confirm);
        startTv = getViewById(R.id.tv_order_start_time);
        endTv = getViewById(R.id.tv_order_end_time);

        queryView = getViewById(R.id.ll_order_query);
        resultView = getViewById(R.id.layout_result);

        resultLv = getViewById(R.id.lv_order_result);

    }

    @Override
    protected void eventOnClick() {

        titleBar.setRightTextView("重置");
        titleBar.setRightTextColor(R.color.unify_grounding_white);
        titleBar.setShowRight(View.VISIBLE);
        titleBar.setRightOnClickListener(this);

        statusRg.setOnCheckedChangeListener(this);
        statusRg.getChildAt(0).performClick();
        confirmBtn.setOnClickListener(this);

        TimeUtils.selectTime(this, startTv, TimeUtils.DATE);
        TimeUtils.selectTime(this, endTv, TimeUtils.DATE);

        adapter = new OrderResultAdapter(this);
        list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            OrderResult result = new OrderResult("张三", "超级刷", "待进件");
            list.add(result);
        }
        adapter.addAll(list);
        resultLv.setAdapter(adapter);

    }

    @Override
    public void onRightClick(View view) {
        rightText = titleBar.getRightText();
        if ("重置".equals(rightText)) {
            startTv.setText("");
            endTv.setText("");
        }
        if ("查询".equals(rightText)) {
            queryView.setVisibility(View.VISIBLE);
            resultView.setVisibility(View.GONE);
            titleBar.setRightTextView("重置");
            titleBar.setRightTextColor(R.color.unify_grounding_white);
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_order_into:
                status = "待进件";
                break;
            case R.id.rbtn_order_complete:
                status = "完成";
                break;
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_order_confirm:
                queryView.setVisibility(View.GONE);
                resultView.setVisibility(View.VISIBLE);
                titleBar.setRightTextView("查询");
                titleBar.setRightTextColor(R.color.unify_grounding_white);
                startTime = startTv.getText().toString();
                endTime = endTv.getText().toString();
                break;
        }
    }
}
